Skip to content

feat(getRandomUser): endpoint get Random user#15

Merged
Theo-lbg merged 11 commits into
mainfrom
feat/getRandomUser
Mar 3, 2026
Merged

feat(getRandomUser): endpoint get Random user#15
Theo-lbg merged 11 commits into
mainfrom
feat/getRandomUser

Conversation

@Theo-lbg

@Theo-lbg Theo-lbg commented Feb 27, 2026

Copy link
Copy Markdown
Collaborator

Swagger :
image

Archi du projet:
image

@Theo-lbg Theo-lbg linked an issue Feb 27, 2026 that may be closed by this pull request
@Theo-lbg Theo-lbg force-pushed the feat/getRandomUser branch 2 times, most recently from d25827e to faf4647 Compare February 27, 2026 09:45
Comment thread src/main/resources/application.properties Outdated
@MayuriXx

Copy link
Copy Markdown
Collaborator

C'est un très bon premier jet en tout cas, bien joué 👍🏻

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request implements a new REST API endpoint to fetch random users from the external Random User API (https://randomuser.me/) and persist them to a PostgreSQL database. The implementation follows Clean Architecture principles with clear separation between presentation, domain, and data layers, and includes Docker Compose configuration for local database setup.

Changes:

  • Added GET /user/random endpoint that fetches and saves random users with configurable count parameter (default: 500)
  • Implemented PostgreSQL database integration with Spring Data JDBC and schema initialization
  • Integrated Retrofit HTTP client to consume the external Random User API
  • Added comprehensive Swagger/OpenAPI documentation for the new endpoint

Reviewed changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 18 comments.

Show a summary per file
File Description
src/main/resources/schema.sql Database schema for user_entity table with fields for user data
src/main/resources/application.properties Added database connection configuration and Random User API URL
src/main/java/.../presentation/handlers/UserHandler.java REST controller handler implementing the getRandomUsers endpoint
src/main/java/.../presentation/controllers/UserController.java Interface defining the API contract with Swagger annotations
src/main/java/.../domain/usecases/FetchAndSaveRandomUsersUseCase.java Business logic for fetching from API and saving to database
src/main/java/.../domain/services/UserService.java Domain service interface for user persistence operations
src/main/java/.../domain/entities/UserEntity.java Domain entity representing a user
src/main/java/.../data/sources/RandomUserRetrofitClient.java Retrofit client configuration for external API calls
src/main/java/.../data/sources/RandomUserApi.java Retrofit API interface for Random User endpoints
src/main/java/.../data/services/UserServiceImpl.java Implementation of UserService using Spring Data repository
src/main/java/.../data/repositories/UserRepository.java Spring Data JDBC repository for UserEntity
src/main/java/.../data/models/RandomUserResultDAO.java DAO for individual user result from API
src/main/java/.../data/models/RandomUserResponseDAO.java DAO for API response wrapper
src/main/java/.../data/models/RandomUserPictureDAO.java DAO for user picture data
src/main/java/.../data/models/RandomUserNameDAO.java DAO for user name data
src/main/java/.../data/models/RandomUserInfoDAO.java DAO for API metadata
src/main/java/.../data/converters/UserConverter.java Converts between DAO and domain entity
pom.xml Added Retrofit converter-gson dependency and enabled spring-boot-starter-data-jdbc
docker-compose.yaml PostgreSQL container configuration with schema initialization
README.md Updated checklist marking the endpoint implementation as complete

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pom.xml Outdated
Comment thread src/main/resources/application.properties Outdated
Comment thread docker-compose.yaml Outdated

@PiotrFLEURY PiotrFLEURY left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quelques modifications à prévoir

Comment thread src/main/resources/application.properties Outdated
Comment thread src/main/resources/schema.sql Outdated
Copilot AI review requested due to automatic review settings March 2, 2026 09:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 31 out of 32 changed files in this pull request and generated 12 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/main/resources/schema.sql Outdated
@Theo-lbg Theo-lbg force-pushed the feat/getRandomUser branch from 732ed1c to 5bdb66c Compare March 2, 2026 10:37
Copilot AI review requested due to automatic review settings March 2, 2026 15:08
@Theo-lbg Theo-lbg force-pushed the feat/getRandomUser branch from df73944 to 86b3bac Compare March 2, 2026 15:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 32 out of 33 changed files in this pull request and generated 8 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/main/resources/application-local.properties
Comment thread README.md
Copilot AI review requested due to automatic review settings March 2, 2026 15:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 32 out of 33 changed files in this pull request and generated 7 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread README.md

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 32 out of 33 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread README.md
Copilot AI review requested due to automatic review settings March 3, 2026 09:44
@sonarqube-xpeho

Copy link
Copy Markdown

@Theo-lbg Theo-lbg merged commit 3380620 into main Mar 3, 2026
6 checks passed
@Theo-lbg Theo-lbg deleted the feat/getRandomUser branch March 3, 2026 09:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 30 out of 31 changed files in this pull request and generated 9 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1 to +10

spring.application.name=spring_boot_java_random_user
# Swagger UI custom path
springdoc.swagger-ui.path=/api
# URL for Random User API
randomuser.api.base-url=https://dummyjson.com/

spring.datasource.url=jdbc:postgresql://localhost:${POSTGRES_PORT}/${POSTGRES_DB}
spring.datasource.username=${POSTGRES_USER}
spring.datasource.password=${POSTGRES_PASSWORD} No newline at end of file

Copilot AI Mar 3, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is committed to the repository, but .gitignore also ignores application-local.properties. If this file is meant to be developer-specific, it should not be committed (provide a .template instead). If it is meant to be an example/default, remove the ignore rule so updates are tracked consistently.

Copilot uses AI. Check for mistakes.
Comment on lines +50 to +57
@Test
@DisplayName("Should handle null response gracefully")
void shouldHandleNullResponseGracefully() throws IOException {
when(randomUserProvider.fetchRandomUsers(1)).thenReturn(null);
when(userService.saveAll(null)).thenReturn(null);
List<UserEntity> result = useCase.execute(1);
assertNull(result);
}

Copilot AI Mar 3, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test enforces that a null provider response should be handled and propagated as null. In production, RandomUserProviderImpl throws when the response/users list is null and UserServiceImpl.saveAll NPEs on null input, so this test is currently encoding behavior that the real implementation does not support. Please either remove/update the test or update the production code to explicitly support null (preferably by returning an empty list or throwing a clear exception).

Copilot uses AI. Check for mistakes.
Comment on lines +32 to +35
List<UserEntity> fetched = List.of(new UserEntity(
1L, "male", "John", "Doe", "Mr", "john@doe.com", "1234", "pic.jpg", "FR"
)); when(randomUserProvider.fetchRandomUsers(2)).thenReturn(fetched);
when(userService.saveAll(fetched)).thenReturn(fetched);

Copilot AI Mar 3, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor readability issue: the stub setup when(randomUserProvider.fetchRandomUsers(2))... is on the same line as the List.of(...) closing. Please put it on a new properly-indented line so the test is easier to read/maintain.

Copilot uses AI. Check for mistakes.
Comment thread README.md
- [ ] [Add this endpoint PUT /user/{id}](https://github.com/XPEHO/spring_boot_java_random_user/issues/9)
- [ ] [Add this endpoint DELETE /user/{id}](https://github.com/XPEHO/spring_boot_java_random_user/issues/10)
- [ ] [Add this endpoint POST /user](https://github.com/XPEHO/spring_boot_java_random_user/issues/11)
- [X] [Add this endpoint get /user/random](https://github.com/XPEHO/spring_boot_java_random_user/issues/5)

Copilot AI Mar 3, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The README marks GET /user/random as implemented, but the only controller mapping introduced is /random-users (see @RequestMapping("/random-users")). Please update either the API route or this checklist entry so they match.

Suggested change
- [X] [Add this endpoint get /user/random](https://github.com/XPEHO/spring_boot_java_random_user/issues/5)
- [X] [Add this endpoint get /random-users](https://github.com/XPEHO/spring_boot_java_random_user/issues/5)

Copilot uses AI. Check for mistakes.
Comment on lines +3 to +8
public class RandomUserNameDAO {
private String title;
private String first;
private String last;

public String getTitle() { return title; }

Copilot AI Mar 3, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This API model class appears unused in the production code (only referenced by its own test). If the project is now using the DummyJSON /users schema (flat firstName/lastName/image), consider removing this class (and its test) to avoid dead code, or wire it into the actual API response model if it's still needed.

Copilot uses AI. Check for mistakes.
}

@Override
public List<UserEntity> saveAll(List<UserEntity> users) {

Copilot AI Mar 3, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saveAll will throw a NullPointerException if users is null (users.stream()). Either enforce non-null at the service boundary (e.g., validate and throw an IllegalArgumentException) or make this method null-safe (e.g., treat null as an empty list) so the contract is explicit and consistent with callers/tests.

Suggested change
public List<UserEntity> saveAll(List<UserEntity> users) {
public List<UserEntity> saveAll(List<UserEntity> users) {
if (users == null) {
throw new IllegalArgumentException("users must not be null");
}

Copilot uses AI. Check for mistakes.
when(randomUserApi.getRandomUsers(count)).thenReturn(call);
when(call.execute()).thenReturn(Response.success(null));
assertThrows(IOException.class, () -> provider.fetchRandomUsers(count));
}

Copilot AI Mar 3, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RandomUserProviderImpl has an explicit branch that throws when response.body() is non-null but response.body().getUsers() is null, but there is no test covering that branch. Please add a test case where Response.success(responseObj) is returned with responseObj.setUsers(null) and assert that an IOException is thrown.

Suggested change
}
}
@Test
@DisplayName("Should throw IOException when response body has null users list")
void shouldThrowIOExceptionWhenResponseBodyHasNullUsersList() throws IOException {
int count = 1;
RandomUserResponse responseObj = new RandomUserResponse();
responseObj.setUsers(null);
when(randomUserApi.getRandomUsers(count)).thenReturn(call);
when(call.execute()).thenReturn(Response.success(responseObj));
assertThrows(IOException.class, () -> provider.fetchRandomUsers(count));
}

Copilot uses AI. Check for mistakes.
Comment on lines +3 to +6
public class RandomUserPictureDAO {
private String medium;

public String getMedium() {

Copilot AI Mar 3, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This API model class appears unused in the production code (only referenced by its own test). If the project is now using the DummyJSON /users schema (single image field), consider removing this class (and its test) to avoid dead code, or integrate it into the API response model if it is still intended to be used.

Copilot uses AI. Check for mistakes.
Comment on lines +19 to +20
@RequestMapping("/random-users")
@Tag(name = "User", description = "Endpoints for random user generation")

Copilot AI Mar 3, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The endpoint is mapped to /random-users, but the README todo checklist (issue #5) states the implemented endpoint should be GET /user/random. Either update the controller mapping to match the documented/expected route, or update the README/issue references so the API contract is consistent.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add this endpoint get /users/random

5 participants